package cn.tedu.api;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

//测试 Collection接口的方法
public class Test3_Collection {
    public static void main(String[] args) {
        Collection<Integer> c = new ArrayList<>();

        c.add(1);
        c.add(2);
        c.add(3);
        c.add(4);
        System.out.println(c);
//        c.clear();

        System.out.println(c.contains(3));
        System.out.println(c.equals("1234"));
        System.out.println(c.hashCode());
        System.out.println(c.isEmpty());
        System.out.println(c.remove(2));
        System.out.println(c.size());

        Object[] objs  = c.toArray();
        System.out.println(Arrays.toString(objs));

        Collection<Integer> c2 = new ArrayList<>();
        c2.add(1);
        c2.add(2);
        System.out.println(c.addAll(c2));
        System.out.println(c);
        System.out.println(c.containsAll(c2));
//        System.out.println(c.removeAll(c2));
//        System.out.println(c);
//        System.out.println(c2);
        System.out.println(c.retainAll(c2));
        System.out.println(c);

        //迭代集合
        Iterator<Integer> it = c.iterator();

        while (it.hasNext()){
            Integer i = it.next();
            System.out.println(i);
        }
    }
}
